<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <!--<a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="协议类型">
              <j-input placeholder="请输入协议类型" v-model="queryParam.fileType"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>-->
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
<!--      <a-button type="primary" icon="download" @click="handleExportXls('合同模版主表')">导出</a-button>-->
<!--      <a-button type="primary" icon="import" @click="downLoadPdf(downContractPdf,0,'',strSelectedRowKeys)"  >下载合同</a-button>-->
      <!-- 高级查询区域 -->
      <a-button type="primary" icon="download" @click="downloaDcontractTemplate(0)" >导出框架协议模板</a-button>
      <a-button type="primary" icon="download" @click="downloaDcontractTemplate(1)" >导出附加协议模板</a-button>
      <a-button type="primary" icon="download" @click="downloaDcontractTemplate(4)" >附加协议模板-对赌多阶梯</a-button>
      <a-button type="primary" icon="download" @click="downloaDcontractTemplate(2)" >导出标准价格模板</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入Excel</a-button>
      </a-upload>
<!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
<!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>-->

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">

          <a @click="downLoadPdf(downContractPdf,0,record.fileType,record.id)" >批量下载</a>
          <a-divider v-if="!record.transfState && record.fileType == '附加协议-对赌多阶梯' && record.spStatus == 2" type="vertical" />
          <a v-if="!record.transfState && record.fileType == '附加协议-对赌多阶梯' && record.spStatus == 2"  @click="handleTransfRule(record.id)" >转规则</a>
<!--          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

        <!--  text  必须使用{{}}两个花括号包起来    -->
        <span slot="dataClick" slot-scope="text, record">
          <a @click="downLoadExcel(record.fileUrl)" style="color: #1890FF" >{{ text }}</a>
        </span>

      <!-- 字符串超长截取省略号显示 -->
        <span slot="fileContent" slot-scope="text">
          <j-ellipsis :value="text" :length="20"/>
        </span>

      </a-table>
    </div>

    <hl-contract-template-modal ref="modalForm" @ok="modalFormOk"></hl-contract-template-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HlContractTemplateModal from './modules/HlContractTemplateModal'

  export default {
    name: 'HlContractTemplateList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      HlContractTemplateModal
    },
    data () {
      return {
        description: '合同模版主表管理页面',
        queryParam:{
          fileType:"附加协议,框架协议,标准协议,附加协议-对赌多阶梯"
        },
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'源excel',
            align:"left",
            dataIndex: 'name',
            scopedSlots: { customRender: 'dataClick' },
            /*formatter: function(record) {
              if (typeof(record.value)[2] == "undefined") {
                return record.name + ' : ' + record.value;
              } else {
                return record.name + ' : ' + record.value[2];
              }
            },*/

          },
          /* {
             title:'模版URL',
             align:"center",
             dataIndex: 'fileUrl'

           },
        /* {
             title:'文件内容',
             align:"center",
             dataIndex: 'fileContent',
             scopedSlots: { customRender: 'fileContent' }
           },*/
          {
            title:'协议类型',
            align:"center",
            dataIndex: 'fileType'
          },
          {
            title:'上传时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'上传人',
            align:"center",
            dataIndex: 'createBy_dictText'
          },
          {
            title:'是否已转规则',
            align:"center",
            dataIndex: 'transfState_dictText'
          },
          /*,{
            title:'审批状态',
            align:"center",
            dataIndex: 'spStatus'
          },*/
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/contract/hlContractTemplate/list",
          delete: "/contract/hlContractTemplate/delete",
          deleteBatch: "/contract/hlContractTemplate/deleteBatch",
          exportXlsUrl: "/contract/hlContractTemplate/exportXls",
          downContractPdf: "contract/hlContractTemplate/downContractPdf",
          importExcelUrl: "contract/hlContractTemplate/importExcelModel",
          transfRuleUrl: "contract/hlContractTemplate/transfRule",

        },
        dictOptions:{},
        superFieldList:[],
        selectedRowKeys:[],
        strSelectedRowKeys:''//多选后的id字符串值
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
      downContractPdf: function(){
        return `${window._CONFIG['domianURL']}/${this.url.downContractPdf}`;
      },
      transfRuleUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.transfRuleUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'name',text:'源excel',dictCode:''})
        fieldList.push({type:'string',value:'fileUrl',text:'模版URL',dictCode:''})
        fieldList.push({type:'Text',value:'fileContent',text:'文件内容',dictCode:''})
        fieldList.push({type:'string',value:'fileType',text:'协议类型',dictCode:''})
        fieldList.push({type:'int',value:'transfState',text:'是否已转规则',dictCode:'yn'})
        fieldList.push({type:'int',value:'spStatus',text:'审批状态',dictCode:''})
        this.superFieldList = fieldList
      },
      onSelectChange(selectedRowKeys) {
        console.log('selectedRowKeys changed: ', selectedRowKeys);
        this.selectedRowKeys = selectedRowKeys
        this.strSelectedRowKeys=selectedRowKeys.join(',')
        console.log(this.strSelectedRowKeys)
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>